<template>
  <view>
    <!--#ifdef APP-PLUS-->
    <view class="lz-status_bar">
      <view class="lz-top_view"></view>
    </view>
    <!--#endif-->
    <!-- #ifndef MP-WEIXIN -->
    <view class="kaoshi-head-top">
      <view class="kaoshi-head-left">
        <navigator open-type="navigateBack" @tap="$navigateBack">
          <view class="iconfont icon-zuojiantou"></view>
        </navigator>
      </view>
    </view>
    <!--#endif-->
    <view class="kaoshi-subject">
      <view class="kaoshi-subject-title">
        <view>全部科目</view>
        <view class="kaoshi-subject-about">点击切换科目</view>
      </view>
      <view class="kaoshi-subject-content">
        <view v-for="(item, index) in list" :key="index"
              class="kaoshi-subject-content-flex" :class="{ 'kaoshi-subject-active' : Subject_id == item.id }"
              @tap="tap_handle_choice_subject(list[index])">
          <view>{{ item.subject_name }}</view>
        </view>
      </view>
    </view>
  </view>
</template>
<script>
import uniNavBar from '@/components/uni-nav-bar/uni-nav-bar.vue'
import { mapState } from 'vuex'
export default {
  data () {
    return {
      list: [],//科目列表
      Subject_id:0,//已选的科目id
    }
  },
  onShow () {
    // 获取科目列表
    this.getSub()
    this.Subject_id = this.subject.id
  },
  computed: {
    ...mapState(['subject'])
  },
  components: {
    uniNavBar
  },
  methods: {
    async getSub () {
      let res = await this.$myHttp.post({
        url: this.$myHttp.urlMap.subjectList,
        data: {
          page:1,
          limit:0
        }
      })
      if (res.code === 1) {
        this.list = res.data.data
      }
    },
    tap_handle_choice_subject (item) {
      this.$store.commit('setSubject', { subject: { id: item.id, subject_name: item.subject_name } })
      this.$myUtils.$router.switchTab({
        url: '/pages/index/index'
      })
    }
  }
}
</script>
<style>
  page{background: #fff}
  .kaoshi-head-left .icon-zuojiantou {
      color: #888;
  }
  .kaoshi-subject {
    padding-top: 12px;
    background: #fff;
  }
  .kaoshi-subject-title{
    width: 88%;
    font-size: 20px;
    font-weight: bold;
    color: #3c464f;
    margin: 0 auto;
  }
  .kaoshi-subject-about{
    font-size: 14px;
    color: #bbb;
    font-weight: normal;
    margin: 4px 0;
  }
  .kaoshi-subject-content {
    width: 90%;
    margin: 0 auto;
    margin-top: 20px;
    display: flex;
    flex-wrap: wrap;
    justify-content: space-between;
  }
  .kaoshi-subject-content-flex {
    display: flex;
    align-items: center;
    justify-content: center;
    background-color:#f3f3f3;
    color: #4a4a4a;
    min-width: 36%;
    padding: 12px 16px;
    font-size: 16px;
    border-radius: 34px;
    margin-bottom: 24px;
  }
  .kaoshi-subject-active {
    background-color: #3c7bfc;
    color: #fff;
  }

</style>
